<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="service.*" %>
<%@ page import="vo.*" %>

<%
	int maxPageItemsCount = 15;
	
	MessageService ms = new MessageServiceImpl();
	
	String pageString = (String) request.getParameter("page");
	int pageNo = Integer.parseInt(pageString);
	MessageListPage mlp = ms.getMessagePageList(null, pageNo, maxPageItemsCount);
	
	int pageCount = mlp.getPageCount();
	int pageItemsCount = mlp.getPageItemsCount();
	String list = "{'page_count':'" + pageCount + "',";
	list += "'page_items_count':'" + pageItemsCount + "',";
	list += "'messages':[";
	for (int i = 1; i <= pageItemsCount; i++) {
		list += "{'no':'" + mlp.getItemNo(i - 1) + "',";
		list += "'title':'" + mlp.getItemTitle(i - 1) + "',";
		list += "'type':'" + mlp.getItemType(i - 1) + "',";
		list += "'replied':'" + mlp.isItemReplied(i - 1) + "'}";
		if (i < pageItemsCount) {
			list += ",";
		}
	}
	list += "]}";
	out.print(list);
%>